package client;

/**
 * Thread zaduzen za pisanje podataka u stream, tj. slanje podataka od klijenta ka serveru.
 * Thread je blokiran (wait()) u getMessage() metodi, sve dok se ne pozove setMessage()
 * metod. Nakon toga, poruka se vraca getMessage() metodom i upisuje se u stream.
 * 
 * @author UrosKrkic & Radivoje Popovic
 */
public class ClientThreadWriter extends Thread {

	/**
	 * Referenca na socket konekciju.
	 */
	private ClientSocketConnection connection;
	
	
	/**
	 * Konstruktor.
	 * @param connection - referenca na socket konekiciju
	 * @author UrosKrkic & Radivoje Popovic
	 */
	public ClientThreadWriter(ClientSocketConnection connection) {
		this.connection = connection;
		this.start();
	}
	
	
	@Override
	public void run() {
		try {
			String message;

			while ( (message = connection.getMessage()) != null ) {
				connection.writeData(message);
			}
		}
		catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
}
